package com.pei.Servlet;


import com.pei.Service.Impl.regionServiceImpl;
import com.pei.Service.Impl.userServiceImpl;
import com.pei.Service.regionService;
import com.pei.Service.userService;
import com.pei.entity.user;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dell on 2018/8/7.
 */
@WebServlet(name = "adduserServlet")
public class adduserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        userService service=new userServiceImpl();
        regionService service1=new regionServiceImpl();
        user u=new user();
        request.setCharacterEncoding("utf-8");
        u.setUname(request.getParameter("uname"));
        u.setUphone(request.getParameter("uphone"));
        u.setUpasswrod(request.getParameter("upasswrod"));
        String province=request.getParameter("province");
        String city=request.getParameter("city");
        String area=request.getParameter("area");
        u.setUprovince(service1.findByIdregion(province));
        u.setUcity(service1.findByIdregion(city));
        u.setUcounty(service1.findByIdregion(area));
        u.setUaddress(request.getParameter("uaddress"));
        u.setUsex(request.getParameter("usex"));
        u.setCreateTime(request.getParameter("createTime"));
        u.setOpenid(request.getParameter("openid"));
        u.setCheck(Integer.parseInt(request.getParameter("check")));
        u.setUemail(request.getParameter("uemail"));
        if (Integer.parseInt(request.getParameter("idd"))==1){
            service.adduser(u,3);
        }
        if (Integer.parseInt(request.getParameter("idd"))==2){
            service.adduser(u,6);
        }
        response.sendRedirect("echarts1.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
